// components/keyboard/keyboard.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    amount: {
      type: String,
      value: ''
    },
    nthText: {
      type: String,
      value: '确认'
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    currentId: '',
    isNext: true,//是否能继续输入
  },
  attached() {
    console.log('amount', this.properties.amount)
  },
  /**
   * 组件的方法列表
   */
  methods: {
    handleStart(e) {
      var id = e.currentTarget.dataset.id
      var amount = this.properties.amount
      amount = amount + id
      if (amount.indexOf(".") != -1 && amount.toString().split(".")[1].length > 2) { //限制最多输入两位小数
        wx.showToast({
          title: '最多输入两位小数',
          icon: 'none'
        })
        return
      }
      if (amount.indexOf(".") != -1) { //判断是否有小数点
        this.setData({
          isNext: false,
        })
      }else{
        this.setData({
          isNext: true,
        })
      }
      this.setData({
        currentId: id,
        amount: amount
      })
      this.triggerEvent("amountData", amount)
      // console.log('amount',this.properties.amount)
    },
    handleEnd() {
      this.setData({
        currentId: ''
      })
    },
    //删除
    handleDetele() {
      var amount = this.properties.amount
      amount = amount.substr(0, amount.length - 1)
      if (amount.indexOf(".") != -1) { //判断是否有小数点
        this.setData({
          isNext: false,
        })
      }else{
        this.setData({
          isNext: true,
        })
      }
      this.setData({
        amount: amount
      })
      this.triggerEvent("amountData", amount)
    },
    //确认支付
    handlePay() {
      this.triggerEvent("handlePay")
    },
  }
})